<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/select2/css/core.css"/>
</head>
<body  class="fixed-header theme-blue-gradient">
<div   id="theme-wrapper">
    <include file="./Application/Home/View/Tpl/header.html" />

    <div id="page-wrapper" class="container">
        <div class="row">
            <include file="./Application/Home/View/Tpl/menu.html"/>

            <div id="content-wrapper">
                <BR>
                <div class="row">
                    <include file="./Application/Home/View/Tpl/alert.html"/>

                    <div class="row">
                        <div class="panel">
                            <div class="panel-heading">
                                    <span class="panel-icon">
                                        <i class="imoon imoon-tab"></i>
                                    </span>
                                <span class="panel-title">旁路监听状态
                                    <span class="label  label-primary passbystatus">获取中...</span>
                                </span>

                            </div>
                            <div class="panel-body pn">
                                <div class="deviceList">
                                    <form id="setPass" role="form">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h4 class="modal-title">旁路监听设置（最多支持三路同时监听，如不需要可只选一路或二路监听）</h4>
                                            </div>
                                            <div class="modal-body">
                                                <div class="admin-form clearfix">
                                                    <div class="section mb10 col-md-12">
                                                        <label for="ssid1" class="col-xs-12 field-label text-center pull-left lh40 txt-lt">一路监听：</label>
                                                        <div class="col-md-4 col-xs-3">
                                                            <label for="ssid1" class="field">
                                                                <input type="text" id="ssid1" name="ssid1" placeholder="一路监听SSID..." class="form-control">
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-2">
                                                            <label for="mod1" class="field">
                                                                <select id="mod1" name="mod1" class="selectclass" data-placeholder="加密方式..." style="width: 100px;;">
                                                                    <option value="0">WPA</option>
                                                                    <option value="1">WEP</option>
                                                                    <option value="2">OPEN</option>
                                                                </select>
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-3">
                                                            <label for="channel1" class="field">
                                                                <input type="tel" id="channel1" name="channel1" placeholder="监听信道..." class="form-control">
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-3">
                                                            <label for="encrypt1" class="field">
                                                                <input type="text" id="encrypt1" name="encrypt1" placeholder="SSID秘钥..." class="form-control">
                                                            </label>
                                                        </div><div class="label label-danger">必选</div>
                                                    </div>

                                                </div>
                                                <div class="admin-form clearfix">
                                                    <div class="section mb10 col-md-12">
                                                        <label for="ssid1" class="col-xs-12 field-label text-center pull-left lh40 txt-lt">二路监听：</label>
                                                        <div class="col-md-4 col-xs-3">
                                                            <label for="ssid2" class="field">
                                                                <input type="text" id="ssid2" name="ssid2" placeholder="二路监听SSID..." class="form-control">
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-2">
                                                            <label for="mod2" class="field">
                                                                <select id="mod2" name="mod2" class="selectclass" data-placeholder="加密方式..." style="width: 100px;">
                                                                    <option value="0">WPA</option>
                                                                    <option value="1">WEP</option>
                                                                    <option value="2">OPEN</option>
                                                                </select>
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-3">
                                                            <label for="channel2" class="field">
                                                                <input type="tel" id="channel2" name="channel2" placeholder="监听信道..." class="form-control">
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-3">
                                                            <label for="encrypt2" class="field">
                                                                <input type="text" id="encrypt2" name="encrypt2" placeholder="SSID秘钥..." class="form-control">
                                                            </label>
                                                        </div><div class="label label-primary">可选</div>
                                                    </div>

                                                </div>
                                                <div class="admin-form clearfix">
                                                    <div class="section mb10 col-md-12">
                                                        <label for="ssid1" class="col-xs-12 field-label text-center pull-left lh40 txt-lt">三路监听：</label>
                                                        <div class="col-md-4 col-xs-3">
                                                            <label for="ssid1" class="field">
                                                                <input type="text" id="ssid3" name="ssid3" placeholder="三路监听SSID..." class="form-control">
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-2">
                                                            <label for="mod3" class="field">
                                                                <select id="mod3" name="mod3" class="selectclass" data-placeholder="加密方式..." style="width:  100px;;">
                                                                    <option value="0">WPA</option>
                                                                    <option value="1">WEP</option>
                                                                    <option value="2">OPEN</option>
                                                                </select>
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-3">
                                                            <label for="channel3" class="field">
                                                                <input type="tel" id="channel3" name="channel3" placeholder="监听信道..." class="form-control">
                                                            </label>
                                                        </div>
                                                        <div class="col-md-2 col-xs-3">
                                                            <label for="encrypt3" class="field">
                                                                <input type="text" id="encrypt3" name="encrypt3" placeholder="SSID秘钥..." class="form-control">
                                                            </label>
                                                        </div><div class="label label-primary">可选</div>
                                                    </div>

                                                </div>
                                                <div  class="admin-form clearfix">
                                                    <div class=" section mb10 col-md-11">
                                                        <div class="alert alert-danger alert-dismissable alertmessage" style="display:none;">
                                                            <h4><strong>提示</strong></h4>
                                                            <p class="alertmessage-text"></p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="modal-footer">
                                                <button type="submit" class="btn btn-lg btn-primary" id="openbtn">开启监听</button>
                                            </div>
                                        </div><!-- /.modal-content -->
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <include file="./Application/Home/View/Tpl/footer.html"/>

            </div>
        </div>

    </div>
</div>
<!-- ./wrapper -->




<include file="./Application/Home/View/Tpl/commjs.html" />
<script src="__PUBLIC__/plugins/select2/select2.min.js"></script>
<script src="__PUBLIC__/js/modernizr.js"></script>
<script src="__PUBLIC__/datatable/datatables.min.js"></script>
<script src="__PUBLIC__/datatable/dataTables.bootstrap.js"></script>
<script src="__PUBLIC__/plugins/confirm/confirm.js"></script>
<!-- PNotify -->
<script src="__PUBLIC__/plugins/pnotify/pnotify.js"></script>



<script>
    $(document).ready(function () {
        $(".selectclass").select2();

        //操作提示信息
        function Msg(flag,text){
            if(flag){
                new PNotify({
                    title: '提示信息',
                    text: text,
                    shadow: true,
                    opacity: 1,
                    addclass: 'stack_top_right',
                    type: 'success',
                    stack: {
                        "dir1": "down",
                        "dir2": "left",
                        "push": "top",
                        "spacing1": 10,
                        "spacing2": 10
                    },
                    width: '400px',
                    delay: 3000
                });
            }else{
                new PNotify({
                    title: '提示信息',
                    text: text,
                    shadow: true,
                    opacity: 1,
                    addclass: 'stack_top_right',
                    type: 'danger',
                    stack: {
                        "dir1": "down",
                        "dir2": "left",
                        "push": "top",
                        "spacing1": 10,
                        "spacing2": 10
                    },
                    width: '400px',
                    delay: 3000
                });
            }
        }

        var passbystatus='close';
        //获取当前设备的旁路监听数据
        $.ajax({
            url : "{:U('/Home/Asidemonitor/getPass','',false)}",
            type : "post",
            dataType : "json",
            data:  {deviceserialno:'self'},
            success:function(result){
                if(result.length>0){
                    passbystatus='open';
                    $("#ssid1").val(result[0].ssid1);
                    $("#mod1").select2('val',result[0].mod1);
                    $("#channel1").val(result[0].channel1);
                    $("#encrypt1").val(result[0].encrypt1);

                    $("#ssid2").val(result[0].ssid2);
                    $("#mod2").select2('val',result[0].mod2);
                    $("#channel2").val(result[0].channel2);
                    $("#encrypt2").val(result[0].encrypt2);

                    $("#ssid3").val(result[0].ssid3);
                    $("#mod3").select2('val',result[0].mod3);
                    $("#channel3").val(result[0].channel3);
                    $("#encrypt3").val(result[0].encrypt3);

                    if(result[0].status==0){
                        $("#openbtn").removeClass('btn-primary');
                        $("#openbtn").addClass('btn-danger');
                        $("#openbtn").html('关闭监听');
                        $('.passbystatus').html('开启中...');
                        $(".passbystatus").removeClass('label-danger');
                        $(".passbystatus").addClass('label-default');
                    }
                    else{
                        $("#openbtn").removeClass('btn-danger');
                        $("#openbtn").addClass('btn-primary');
                        $("#openbtn").html('开启监听');
                        $('.passbystatus').html('已关闭');
                        $(".passbystatus").removeClass('label-primary');
                        $(".passbystatus").addClass('label-default');
                    }

                }else{
                    $("#openbtn").removeClass('btn-danger');
                    $("#openbtn").addClass('btn-primary');
                    $("#openbtn").html('开启监听');
                    $('.passbystatus').html('已关闭');
                    $(".passbystatus").removeClass('label-primary');
                    $(".passbystatus").addClass('label-default');
                }
            }
        });



        //修改设备信息
        $("#setPass").validate({
            /*rules:{
             ssid1:{
             required:true,
             maxlength:40
             },
             mod1:{
             required:true
             },
             channel1:{
             required:true,
             digits:true
             }
             },
             messages: {
             ssid1: {
             required:'请输入SSID'
             },
             mod1: {
             required:'请选择加密方式'
             },
             channel1: {
             required:'请输入信道',
             digits:'信道必须为数字'
             },
             },*/
            errorPlacement: function(error, element) {
                error.appendTo(element.parent().parent());
            },
            submitHandler: function(form) {
                if($("#openbtn").hasClass('btn-danger')){
                    $.ajax({
                        url : "{:U('/Home/Asidemonitor/closePass','',false)}",
                        type : "post",
                        dataType : "json",
                        data:  {deviceserialno:'self'},
                        success:function(result){
                            var flag = result.status;
                            var text = flag?'旁路监听关闭成功':'旁路监听关闭失败:'+result.info;
                            Msg(flag,text);
                            if(flag){
                                setTimeout(function () {
                                    window.location.reload();
                                },1000);
                            }
                        }
                    });
                    return;
                }
                setTimeout(function () {
                    $(".alertmessage").hide();
                },4000);
                if($("#ssid1").val()=='' || $("#channel1").val()==''){

                    $(".alertmessage").show();
                    $(".alertmessage-text").html('一路监听配置不完整请核对。');
                    return false;
                }
                if($("#mod1").val()=='0' && ($("#encrypt1").val()=='' || ($("#encrypt1").val()).length<8)){
                    $(".alertmessage").show();
                    $(".alertmessage-text").html('一路监听配置加密方式为WPA必须填写秘钥且秘钥至少8位。');
                    return false;
                }
                //open的ssid，密码都可以不输入，后台我发一个默认密码（长度8位）
                //wep的密码限制必须是5位
                /*<option value="0">WPA</option>
                 <option value="1">WEP</option>
                 <option value="2">OPEN</option>*/
                var encrypt1=$("#encrypt1").val(),encrypt2=$("#encrypt2").val(),encrypt3=$("#encrypt3").val();
                if($("#mod1").val()=='2'){
                    encrypt1='12345678';
                }
                if($("#mod1").val()=='1' && ($("#encrypt1").val()).length!=5){
                    $(".alertmessage").show();
                    $(".alertmessage-text").html('一路监听配置加密方式为WEP必须填写秘钥且秘钥必须为5位。');
                    return false;
                }
                if($("#mod2").val()=='2'){
                    encrypt2='12345678';
                }
                if($("#mod2").val()=='1' && ($("#encrypt2").val()).length!=5){
                    $(".alertmessage").show();
                    $(".alertmessage-text").html('二路监听配置加密方式为WEP必须填写秘钥且秘钥必须为5位。');
                    return false;
                }
                if($("#mod3").val()=='2'){
                    encrypt3='12345678';
                }
                if($("#mod3").val()=='1' && ($("#encrypt3").val()).length!=5){
                    $(".alertmessage").show();
                    $(".alertmessage-text").html('三路监听配置加密方式为WEP必须填写秘钥且秘钥必须为5位。');
                    return false;
                }
                /*if($("#ssid2").val()!='' && $("#channel2").val()==''){
                 $(".alertmessage").show();
                 $(".alertmessage-text").html('二路监听配置不完整请核对。');
                 return false;
                 }*/
                if($("#ssid2").val()!='' && $("#mod2").val()=='0' &&( $("#encrypt2").val()=='' || ($("#encrypt2").val()).length<8)){
                    $(".alertmessage").show();
                    $(".alertmessage-text").html('二路监听配置加密方式为WPA必须填写秘钥且秘钥至少8位。');
                    return false;
                }

                /*if($("#ssid3").val()!='' && $("#channel3").val()==''){
                 $(".alertmessage").show();
                 $(".alertmessage-text").html('三路监听配置不完整请核对。');
                 return false;
                 }*/
                if($("#ssid3").val()!='' && $("#mod3").val()=='0' && ($("#encrypt3").val()=='' || ($("#encrypt3").val()).length<8)){
                    $(".alertmessage").show();
                    $(".alertmessage-text").html('三路监听配置加密方式为WPA必须填写秘钥且秘钥至少8位。');
                    return false;
                }
                /*if($("#ssid2").val()!='' && $("#channel2").val()!=$("#channel1").val()){
                 $(".alertmessage").show();
                 $(".alertmessage-text").html('旁路监听信道必须相同，请检查二路监听和一路监听信道。');
                 return false;
                 }
                 if($("#ssid3").val()!='' && $("#channel3").val()!=$("#channel1").val()){
                 $(".alertmessage").show();
                 $(".alertmessage-text").html('旁路监听信道必须相同，请检查三路监听和一路监听信道。');
                 return false;
                 }*/
                var param = {
                    deviceserialno:'self',
                    ssid1: $("#ssid1").val(),
                    mod1:$("#mod1").val(),
                    channel1:$("#channel1").val(),
                    encrypt1:encrypt1,
                    ssid2: $("#ssid2").val(),
                    mod2:$("#mod2").val(),
                    channel2:$("#channel2").val(),
                    encrypt2:encrypt2,
                    ssid3: $("#ssid3").val(),
                    mod3:$("#mod3").val(),
                    channel3:$("#channel3").val(),
                    encrypt3:encrypt3
                };
                $.ajax({
                    url : "{:U('/Home/Asidemonitor/setPass','',false)}",
                    type : "post",
                    dataType : "json",
                    data:  param,
                    success:function(result){
                        var flag = result.status;
                        var text = flag?'旁路监听设置成功':'旁路监听设置失败:'+result.info;
                        Msg(flag,text);
                        if(flag){
                            setTimeout(function () {
                                window.location.reload();
                            },1000);
                        }
                    }
                });
            },
            invalidHandler: function(form, validator) {  //不通过回调
                return false;
            }
        });

    });
</script>

</body>
</html>


